package intelligent_maintenances

import (
	
	"github.com/flipped-aurora/gin-vue-admin/server/global"
    "github.com/flipped-aurora/gin-vue-admin/server/model/common/response"
    "github.com/flipped-aurora/gin-vue-admin/server/model/intelligent_maintenances"
    intelligent_maintenancesReq "github.com/flipped-aurora/gin-vue-admin/server/model/intelligent_maintenances/request"
    "github.com/gin-gonic/gin"
    "go.uber.org/zap"
)

type IntelligentMaintenanceApi struct {}



// CreateIntelligentMaintenance 创建智能保养
// @Tags IntelligentMaintenance
// @Summary 创建智能保养
// @Security ApiKeyAuth
// @Accept application/json
// @Produce application/json
// @Param data body intelligent_maintenances.IntelligentMaintenance true "创建智能保养"
// @Success 200 {object} response.Response{msg=string} "创建成功"
// @Router /intelligentMaintenance/createIntelligentMaintenance [post]
func (intelligentMaintenanceApi *IntelligentMaintenanceApi) CreateIntelligentMaintenance(c *gin.Context) {
    // 创建业务用Context
    ctx := c.Request.Context()

	var intelligentMaintenance intelligent_maintenances.IntelligentMaintenance
	err := c.ShouldBindJSON(&intelligentMaintenance)
	if err != nil {
		response.FailWithMessage(err.Error(), c)
		return
	}
	err = intelligentMaintenanceService.CreateIntelligentMaintenance(ctx,&intelligentMaintenance)
	if err != nil {
        global.GVA_LOG.Error("创建失败!", zap.Error(err))
		response.FailWithMessage("创建失败:" + err.Error(), c)
		return
	}
    response.OkWithMessage("创建成功", c)
}

// DeleteIntelligentMaintenance 删除智能保养
// @Tags IntelligentMaintenance
// @Summary 删除智能保养
// @Security ApiKeyAuth
// @Accept application/json
// @Produce application/json
// @Param data body intelligent_maintenances.IntelligentMaintenance true "删除智能保养"
// @Success 200 {object} response.Response{msg=string} "删除成功"
// @Router /intelligentMaintenance/deleteIntelligentMaintenance [delete]
func (intelligentMaintenanceApi *IntelligentMaintenanceApi) DeleteIntelligentMaintenance(c *gin.Context) {
    // 创建业务用Context
    ctx := c.Request.Context()

	ID := c.Query("ID")
	err := intelligentMaintenanceService.DeleteIntelligentMaintenance(ctx,ID)
	if err != nil {
        global.GVA_LOG.Error("删除失败!", zap.Error(err))
		response.FailWithMessage("删除失败:" + err.Error(), c)
		return
	}
	response.OkWithMessage("删除成功", c)
}

// DeleteIntelligentMaintenanceByIds 批量删除智能保养
// @Tags IntelligentMaintenance
// @Summary 批量删除智能保养
// @Security ApiKeyAuth
// @Accept application/json
// @Produce application/json
// @Success 200 {object} response.Response{msg=string} "批量删除成功"
// @Router /intelligentMaintenance/deleteIntelligentMaintenanceByIds [delete]
func (intelligentMaintenanceApi *IntelligentMaintenanceApi) DeleteIntelligentMaintenanceByIds(c *gin.Context) {
    // 创建业务用Context
    ctx := c.Request.Context()

	IDs := c.QueryArray("IDs[]")
	err := intelligentMaintenanceService.DeleteIntelligentMaintenanceByIds(ctx,IDs)
	if err != nil {
        global.GVA_LOG.Error("批量删除失败!", zap.Error(err))
		response.FailWithMessage("批量删除失败:" + err.Error(), c)
		return
	}
	response.OkWithMessage("批量删除成功", c)
}

// UpdateIntelligentMaintenance 更新智能保养
// @Tags IntelligentMaintenance
// @Summary 更新智能保养
// @Security ApiKeyAuth
// @Accept application/json
// @Produce application/json
// @Param data body intelligent_maintenances.IntelligentMaintenance true "更新智能保养"
// @Success 200 {object} response.Response{msg=string} "更新成功"
// @Router /intelligentMaintenance/updateIntelligentMaintenance [put]
func (intelligentMaintenanceApi *IntelligentMaintenanceApi) UpdateIntelligentMaintenance(c *gin.Context) {
    // 从ctx获取标准context进行业务行为
    ctx := c.Request.Context()

	var intelligentMaintenance intelligent_maintenances.IntelligentMaintenance
	err := c.ShouldBindJSON(&intelligentMaintenance)
	if err != nil {
		response.FailWithMessage(err.Error(), c)
		return
	}
	err = intelligentMaintenanceService.UpdateIntelligentMaintenance(ctx,intelligentMaintenance)
	if err != nil {
        global.GVA_LOG.Error("更新失败!", zap.Error(err))
		response.FailWithMessage("更新失败:" + err.Error(), c)
		return
	}
	response.OkWithMessage("更新成功", c)
}

// FindIntelligentMaintenance 用id查询智能保养
// @Tags IntelligentMaintenance
// @Summary 用id查询智能保养
// @Security ApiKeyAuth
// @Accept application/json
// @Produce application/json
// @Param ID query uint true "用id查询智能保养"
// @Success 200 {object} response.Response{data=intelligent_maintenances.IntelligentMaintenance,msg=string} "查询成功"
// @Router /intelligentMaintenance/findIntelligentMaintenance [get]
func (intelligentMaintenanceApi *IntelligentMaintenanceApi) FindIntelligentMaintenance(c *gin.Context) {
    // 创建业务用Context
    ctx := c.Request.Context()

	ID := c.Query("ID")
	reintelligentMaintenance, err := intelligentMaintenanceService.GetIntelligentMaintenance(ctx,ID)
	if err != nil {
        global.GVA_LOG.Error("查询失败!", zap.Error(err))
		response.FailWithMessage("查询失败:" + err.Error(), c)
		return
	}
	response.OkWithData(reintelligentMaintenance, c)
}
// GetIntelligentMaintenanceList 分页获取智能保养列表
// @Tags IntelligentMaintenance
// @Summary 分页获取智能保养列表
// @Security ApiKeyAuth
// @Accept application/json
// @Produce application/json
// @Param data query intelligent_maintenancesReq.IntelligentMaintenanceSearch true "分页获取智能保养列表"
// @Success 200 {object} response.Response{data=response.PageResult,msg=string} "获取成功"
// @Router /intelligentMaintenance/getIntelligentMaintenanceList [get]
func (intelligentMaintenanceApi *IntelligentMaintenanceApi) GetIntelligentMaintenanceList(c *gin.Context) {
    // 创建业务用Context
    ctx := c.Request.Context()

	var pageInfo intelligent_maintenancesReq.IntelligentMaintenanceSearch
	err := c.ShouldBindQuery(&pageInfo)
	if err != nil {
		response.FailWithMessage(err.Error(), c)
		return
	}
	list, total, err := intelligentMaintenanceService.GetIntelligentMaintenanceInfoList(ctx,pageInfo)
	if err != nil {
	    global.GVA_LOG.Error("获取失败!", zap.Error(err))
        response.FailWithMessage("获取失败:" + err.Error(), c)
        return
    }
    response.OkWithDetailed(response.PageResult{
        List:     list,
        Total:    total,
        Page:     pageInfo.Page,
        PageSize: pageInfo.PageSize,
    }, "获取成功", c)
}

// GetIntelligentMaintenancePublic 不需要鉴权的智能保养接口
// @Tags IntelligentMaintenance
// @Summary 不需要鉴权的智能保养接口
// @Accept application/json
// @Produce application/json
// @Success 200 {object} response.Response{data=object,msg=string} "获取成功"
// @Router /intelligentMaintenance/getIntelligentMaintenancePublic [get]
func (intelligentMaintenanceApi *IntelligentMaintenanceApi) GetIntelligentMaintenancePublic(c *gin.Context) {
    // 创建业务用Context
    ctx := c.Request.Context()

    // 此接口不需要鉴权
    // 示例为返回了一个固定的消息接口，一般本接口用于C端服务，需要自己实现业务逻辑
    intelligentMaintenanceService.GetIntelligentMaintenancePublic(ctx)
    response.OkWithDetailed(gin.H{
       "info": "不需要鉴权的智能保养接口信息",
    }, "获取成功", c)
}
